/*
 * Copyright (C) 2011 Urals State University,
 * Department of Mathematics and Mechanics
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ru.edu.usu.cs.bubbles.userlistener;

import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

public class UserListener implements OnTouchListener {
    
    private Queue<MotionEvent> mEventQueue;
    public boolean EventCreated;
    
    public UserListener() {
        mEventQueue = new ConcurrentLinkedQueue<MotionEvent>();
    }
    
    @Override
    public boolean onTouch(View view,MotionEvent event) {
        // TODO Auto-generated method stub
        if (event.getAction()==MotionEvent.ACTION_UP) {
            mEventQueue.add(event);
            EventCreated = true;
        }
        return true;
    }
    
    public MotionEvent getEventToProcessing() {
        MotionEvent event = mEventQueue.poll();
        synchronized (mEventQueue) {
            if (mEventQueue.isEmpty()) EventCreated = false;
        }
        return event;
    }

}

